local skel = fk.CreateSkill {
  name = "_emo__niangkou",
}

Fk:loadTranslationTable{
  ["emo__niangkou"] = "酿寇",
  [":emo__niangkou"] = "你可重铸一种牌名的所有基本牌并视为使用攻击范围为等量的【杀】。你需使用但未使用基本牌的阶段结束时，你可使用一张【杀】或摸一张牌。",
  -- 若此阶段你未使用过基本牌，且此阶段存在“当你需要使用一张基本牌时”这个时机
  ["#emo__niangkou"] = "酿寇:重铸一种牌名的所有基本牌并视为使用攻击范围为等量的【杀】",
  ["#emo__niangkou-use"] = "酿寇:你使用一张【杀】，否则摸一张牌",
}

skel:addEffect("viewas", {
  prompt = "#emo__niangkou",
  anim_type = "offensive",
  mute_card = false,
  pattern = "slash",
  interaction = function(self, player)
    local names = {}
    for _, id in ipairs(player:getCardIds("h")) do
      if Fk:getCardById(id).type == Card.TypeBasic then
        table.insertIfNeed(names, Fk:getCardById(id).trueName)
      end
    end
    if #names > 0 then
      return UI.CardNameBox { choices = names }
    end
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  view_as = function (self, player, cards)
    if self.interaction.data == nil then return nil end
    local c = Fk:cloneCard("slash")
    c.skillName = skel.name
    for _, id in ipairs(player:getCardIds("h")) do
      if Fk:getCardById(id).trueName == self.interaction.data then
        c:addFakeSubcard(id)
      end
    end
    if #c.fake_subcards == 0 then return nil end
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:recastCard(use.card.fake_subcards, player, skel.name)
  end,
})

skel:addEffect(fk.EventPhaseEnd, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and
    (player:getMark("emo__niangkou-phase") ~= 0 or (target == player and player.phase == Player.Play))
    and #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data
      return use.from == player and use.card.type == Card.TypeBasic
    end, Player.HistoryPhase) == 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local use = room:askToUseCard(player, {
      pattern = "slash", skill_name = skel.name, prompt = "#emo__niangkou-use", extra_data = {bypass_times = true}
    })
    if use then
      use.extraUse = true
      room:useCard(use)
    else
      player:drawCards(1, skel.name)
    end
  end,
})

skel:addEffect(fk.AskForCardUse, {
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(skel.name, true) and target == player and player:getMark("emo__niangkou-phase") == 0 then
      return Exppattern:Parse(".|.|.|.|.|basic"):matchExp(data.pattern)
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "emo__niangkou-phase", 1)
  end,
})

skel:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card, target)
    if card and table.contains(card.skillNames, skel.name) then
      local x = player:distanceTo(target)
      return x <= #card.fake_subcards
    end
  end,
})

return skel
